import { BaseWindow } from "../../../component/window/BaseWindow";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Language } from "../../../../extend/language/Language";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ObjCreate } from "../common/ObjCreate";
import { GBox } from "../../../../com/mui/containers/GBox";
import { GBoxDirection } from "../../../../com/mui/containers/globalVariable/GBoxDirection";
import { SGuildWarCopyInfo } from "../../../../Message/Public/SGuildWarCopyInfo";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { SceneConfig } from "../../resource/SceneConfig";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { Vector } from "../../../../__AS3__/vec/Vector";
type int = number;
//class GuildWarFlyScene
    
    export  class GuildWarFlyScene extends BaseWindow
    {
        constructor()
        {
            super();
            this.vcBtn = new Vector.<GButton>();
            setSize(256, 263);
            title = Language.getString(41811);
            titleHeight = 26;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            var loc1=new GTextFormat(FontUtil.songtiName, 14, GlobalStyle.color2Uint);
            ObjCreate.createTextField(Language.getString(41812), 22, 46, 210, 24, this, loc1);
            this._bg = ObjCreate.createBg(18, 70, 220, 181, this);
            this._btnBox = new GBox();
            this._btnBox.direction = GBoxDirection.VERTICAL;
            this._btnBox.verticalGap = 4;
            this._btnBox.x = 33;
            this._btnBox.y = 85;
            this.addChild(this._btnBox);
            return;
        }

        /* internal  */clearBtn(): void
        {
            var loc1=0;
            while (loc1 < this.vcBtn.length) 
            {
                this._btnBox.removeChild(this.vcBtn[loc1]);
                ++loc1;
            }
            this.vcBtn = new Vector.<GButton>();
            return;
        }

        /* internal  */createBtn(arg1: string, arg2: SGuildWarCopyInfo): void
        {
            var mapName: string;
            var guildWarCopyInfo: SGuildWarCopyInfo;
            var suffix: string;
            var btn: GButton;
            var textFormatCenter: Object /* flash.text.TextFormat */;
            var textField: Object /* flash.text.TextField */;
            var onBtnClick: Function;

            var loc1;
            suffix = null;
            onBtnClick = null;
            mapName = arg1;
            guildWarCopyInfo = arg2;
            onBtnClick = (arg1: Object /* flash.events.MouseEvent */): void
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarEnter, guildWarCopyInfo.guildWardId));
                hide();
                return;
            }
            if (guildWarCopyInfo.num > 180) 
            {
                suffix = HTMLUtil.addColor(Language.getString(41813), "#F65C60");
            }
            else if (guildWarCopyInfo.num > 100) 
            {
                suffix = HTMLUtil.addColor(Language.getString(41814), "#F8CF4E");
            }
            else 
            {
                suffix = HTMLUtil.addColor(Language.getString(41815), "#22B968");
            }
            btn = ObjCreate.createGButton("", 0, 0, 188, 26, this._btnBox, "ButtonLarge");
            btn.addEventListener(flash.events.MouseEvent.CLICK, onBtnClick, false, 0, true);
            this.vcBtn.push(btn);
            textFormatCenter = new GTextFormat(FontUtil.songtiName, 12, 11661311);
            textFormatCenter.align = flash.text.TextFormatAlign.CENTER;
            textField = ObjCreate.createTextField("", 0, 5, 188, 20, btn, textFormatCenter);
            textField.htmlText = mapName + suffix;
            textField.mouseEnabled = false;
            return;
        }

        public updateCopyList(arg1: int, arg2: Array<any>): void
        {
            var loc1=null;
            var loc2=null;
            var loc4=null;
            this.clearBtn();
            var loc3=0;
            while (loc3 < arg2.length) 
            {
                loc4 = arg2[loc3] as SGuildWarCopyInfo;
                loc1 = SceneConfig.instance.getSceneInfo(loc4.guildWardId);
                loc2 = loc1.sMapDefine.name;
                if (arg1 != loc4.guildWardId) 
                {
                    this.createBtn(loc2, loc4);
                }
                ++loc3;
            }
            this._btnBox.validateNow();
            this._bg.height = this._btnBox.height + 30;
            this.height = this._bg.height + 85;
            return;
        }

        public static get instance(): GuildWarFlyScene
        {
            if (!GuildWarFlyScene._instance) 
            {
                GuildWarFlyScene._instance = new GuildWarFlyScene();
            }
            return GuildWarFlyScene._instance;
        }

        /* internal */ /* var */_btnBox: GBox;

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */vcBtn: Vector.<GButton>;

        /* internal */ static /* var */_instance: GuildWarFlyScene;
    }
